<?php

/*
 * Copyright (C) 2015 ziroom.com
 * 
 * The closest to perfection a person ever comes is when he fills out a job
 * application form.
 * -- Stanley J. Randall
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * This program is created by JIAO Jie.
 * The official website is <http://www.ziroom.com/>
 */

namespace Jiaojie;

use Exception;

/**
 * Base Error
 * @author JIAO Jie
 * @date 2015-5-7
 * @version 1.0.0
 * @description
 */
class Error extends Exception {

    /**
     * Error Map
     * @var array
     * @static 
     */
    protected static $error_map = array(
        '1001' => 'some of the runtime parameters are empty',
        '1002' => 'some of the runtime parameters\'types doesn\'t match the requied ones',
        '1003' => 'no access to such method',
        '2001' => 'the living flag doesn\'t meet the requied one',
        '4001' => 'the program encouters an error while phrsing',
        '4002' => 'mothed returns unexcepted results',
        '9001' => 'an unknown error happened',
    );

    const EMPTY_ERROR = 1001;
    const PARAMETER_TYPE_ERROR = 1002;
    const METHOD_NOT_ALLOW_ERROR = 1003;
    const FLAG_ERROR = 2001;
    const PARSE_ERROR = 4001;
    const METHOD_RETURN_ERROR = 4002;
    const UNKNOWN_ERROR = 9001;

    /**
     * Trigger Exception Description
     * @param integer $code Error Code
     */
    public function __construct($code = static::UNKNOWN_ERROR) {
        parent::__construct(static::$error_map[$code], $code);
    }

}
